package com.wmlive.hhvideo.heihei.bells.presenter;

import android.text.TextUtils;

import com.wmlive.hhvideo.common.base.BasePresenter;
import com.wmlive.hhvideo.heihei.beans.splash.InitCatchData;
import com.wmlive.hhvideo.heihei.beans.main.VideoCommentResponse;
import com.wmlive.hhvideo.heihei.bells.view.BellCommentView;
import com.wmlive.networklib.entity.DCNetObserver;

import static com.wmlive.hhvideo.common.network.HttpConstant.TYPE_FETCH_COMMENT;

/**
 * Created by vhawk on 2017/6/5.
 */

public class BellCommentPresenter extends BasePresenter<BellCommentView> {

    public BellCommentPresenter(BellCommentView view) {
        super(view);
    }

    /**
     * 评论
     *
     * @param videoId
     * @param title
     * @param remindUserId
     * @param replayUserId
     */
    public void commentVideo(final long videoId, String title, String remindUserId, long replayUserId) {

        String url = InitCatchData.opusCommendOpus();
        if (!TextUtils.isEmpty(url)) {
            executeRequest(TYPE_FETCH_COMMENT, getHttpApi()
                    .commentVideo(url,
                            videoId, title, remindUserId, replayUserId))
                    .subscribe(new DCNetObserver<VideoCommentResponse>() {
                        @Override
                        public void onRequestDataReady(int requestCode, String message, VideoCommentResponse response) {

                            if (viewCallback != null) {
                                viewCallback.handleCommentSucceed(response);
                            }
                        }

                        @Override
                        public void onRequestDataError(int requestCode, int serverCode, String message) {
                            if (viewCallback != null) {
                                viewCallback.handleCommentFailure(message);
                            }
                        }
                    });
        } else {
            if (viewCallback != null) {
                viewCallback.handleNetError();
            }
        }


    }

}
